#include <cstdio>
#include <iostream>
#include <csignal>

#include "Launcher.hpp"
#include "common/MyIP.hpp"
const PAN_CHAR_T PANTHEIOS_FE_PROCESS_IDENTITY[] = "efs";

const int default_port = 8080;

using namespace efs;

Launcher *launcher;
bool stop_request = false;

void sigHandler (int sigNum)
{
	pantheios::log_INFORMATIONAL("CTRL-C signal");
	launcher->stop();
	stop_request = true;
}

int main(int argc, char *argv[])
{
	signal(SIGINT, sigHandler);
	MyIP my_ip;

	if (my_ip.getMyIP() == "")
	{
		pantheios::log_ERROR("No net interface");
		return 0;
	}

	Settings settings;
	settings.my_net_settings.ip = my_ip.getMyIP();
	settings.loadCommandLine(argc, argv);
	launcher = new Launcher(settings);

	pantheios::log_INFORMATIONAL("Start");
	launcher->start();
	while (!stop_request)
	{
		sleep(1);
	}

	delete launcher;
	pantheios::log_INFORMATIONAL("Exit");

	return 0;
}




/*
#include <pantheios/pantheios.hpp> //primary header file, always be included
#include <pantheios/frontends/stock.h>
#include <pantheios/inserters/args.hpp>

//Specify process identity
const PAN_CHAR_T PANTHEIOS_FE_PROCESS_IDENTITY[] = "efs";

int main(int argc, char** argv){

//Use pantheios::log_xxx() or pantheios::log(xxx_, ) with xxx_ is severity level

try
{
pantheios::log(pantheios::debug, "Entering main(", pantheios::args(argc, argv, pantheios::args::arg0FileOnly), ")");
pantheios::log_DEBUG("debug");
pantheios::log_INFORMATIONAL("informational");
pantheios::log_NOTICE("notice");
pantheios::log_WARNING("warning");
pantheios::log_ERROR("error");
pantheios::log_CRITICAL("critical");
pantheios::log_ALERT("alert");
pantheios::log_EMERGENCY("emergency");

return 1;
}
catch(std::bad_alloc&){
pantheios::log_ALERT("out of memory");
}
catch(std::exception& x){
pantheios::log_CRITICAL("Exception: ", x);
}
catch(...){
pantheios::puts(pantheios::emergency, "Unknown error");
}

return 2;
}
*/

// Copyright Vladimir Prus 2002-2004.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)

/* The simplest usage of the library.
 */

/*
#include <boost/program_options.hpp>
namespace po = boost::program_options;

#include <iostream>
#include <iterator>
using namespace std;

int main(int ac, char* av[])
{
	po::options_description desc("Allowed options");

    try {

        po::options_description desc("Allowed options");
        desc.add_options()
            ("help", "produce help message")
            ("compression", po::value<int>(), "set compression level")
        ;

        po::variables_map vm;
        po::store(po::parse_command_line(ac, av, desc), vm);
        po::notify(vm);

        if (vm.count("help")) {
            cout << desc << "\n";
            return 1;
        }

        if (vm.count("compression")) {
            cout << "Compression level was set to "
                 << vm["compression"].as<int>() << ".\n";
        } else {
            cout << "Compression level was not set.\n";
        }
    }
    catch(exception& e) {
        cerr << "error: " << e.what() << "\n";
        return 1;
    }
    catch(...) {
        cerr << "Exception of unknown type!\n";
    }

    return 0;
}
*/
